package com.yidu.t299.dao.ssk;
import com.yidu.t299.domain.ssk.School;
import com.yidu.t299.domain.ssk.StuReturnMoney;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;

/**
 * @author 粟术康
 * @version 1.0
 * @description
 * @date:2023/3/17 14:18
 */
@Mapper
public interface StuReturnMoneyMapper {
    /**
     * 添加学员退费信息
     * @param stuReturnMoney 学员退费对象
     * @return 影响的行数(返回1则为成功)
     */
    @Insert({"insert into stu_return_money (return_money_id,student_id,return_money,return_money_date,school_id,record_id,account_id,class_id)" +
            " values " +
            "(#{returnMoneyId,jdbcType=INTEGER}," +
            "#{studentId,jdbcType=INTEGER},"+
            "#{returnMoney,jdbcType=VARCHAR},"+
            "#{returnMoneyDate,jdbcType=VARCHAR},"+
            "#{schoolId,jdbcType=INTEGER},"+
            "#{recordId,jdbcType=INTEGER},"+
            "#{accountId,jdbcType=INTEGER},"+
            "#{classId,jdbcType=INTEGER})"
    })
    int insert(StuReturnMoney stuReturnMoney);
    /**
     * 根据退费编号删除该退费信息
     * @param returnMoneyId 退费编号
     * @return 影响的行数(返回1则为成功)
     */
    @Delete({"delete from stu_return_money" +
            " where return_money_id = #{returnMoneyId,jdbcType=INTEGER}"})
    int deleteByPrimaryKey(Integer returnMoneyId);
    /**
     * 根据退费信息修改其数据
     * @param stuReturnMoney 退费对象
     * @return 影响的行数(返回1则为成功)
     */
    @Update({
            "update stu_return_money" +
                    " set student_id = #{studentId,jdbcType=INTEGER}," +
                    "return_money = #{returnMoney,jdbcType=VARCHAR}," +
                    "return_money_date = #{returnMoneyDate,jdbcType=VARCHAR}," +
                    "school_id = #{schoolId,jdbcType=INTEGER}," +
                    "record_id = #{recordId,jdbcType=INTEGER}," +
                    "account_id = #{accountId,jdbcType=INTEGER}," +
                    "class_id = #{classId,jdbcType=INTEGER}"+
                    " where return_money_id = #{returnMoneyId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(StuReturnMoney stuReturnMoney);
    /**
     * 根据退费编号查询指定的信息
     * @param returnMoneyId 退费编号
     * @return 退费对象
     */
    @Select({
            "select" +
                    " return_money_id,student_id,return_money,return_money_date,school_id,record_id,account_id,class_id" +
                    " from stu_return_money" +
                    " where return_money_id = #{returnMoneyId,jdbcType=INTEGER}"
    })
    @Results(id = "StuReturnMoneyMap",value = {
            @Result(id = true,column = "return_money_id",property = "returnMoneyId" ),
            @Result(column = "student_id",property = "studentId"),
            @Result(column = "return_money",property = "returnMoney"),
            @Result(column = "return_money_date",property = "returnMoneyDate"),
            @Result(column = "school_id",property = "schoolId"),
            @Result(column = "record_id",property = "recordId"),
            @Result(column = "account_id",property = "accountId"),
            @Result(column = "class_id",property = "classId")
    })

    StuReturnMoney selectByPrimaryKey(Integer returnMoneyId);

    /**
     * 按条件分页查询退费数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 退费对象集合
     */
    @Select("SELECT * " +
            "FROM stu_return_money st " +
            "JOIN student_manage s " +
            "ON st.student_id=s.student_id " +
            "JOIN school sh " +
            "ON st.school_id=sh.school_id " +
            "JOIN record r " +
            "ON st.record_id=r.record_id " +
            "JOIN account ac " +
            "ON st.account_id=ac.account_id " +
            "JOIN class c " +
            "ON st.class_id=c.class_id " +
            "where 1=1 ${condition} limit #{page},#{rows}")
    @Results(id = "StuReturnMoneyMaps",value = {
            @Result(column = "return_money_id", property = "returnMoneyId", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "student_id", property = "studentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "return_money", property = "returnMoney", jdbcType = JdbcType.VARCHAR),
            @Result(column = "return_money_date", property = "returnMoneyDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "school_id", property = "schoolId", jdbcType = JdbcType.INTEGER),
            @Result(column = "record_id", property = "recordId", jdbcType = JdbcType.INTEGER),
            @Result(column = "account_id", property = "accountId", jdbcType = JdbcType.INTEGER),
            @Result(column = "class_id", property = "classId", jdbcType = JdbcType.INTEGER),
            @Result(column = "student_name", property = "studentName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "school_name", property = "schoolName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "record_name", property = "recordName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "account_type", property = "accountType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "class_name", property = "className", jdbcType = JdbcType.VARCHAR),
    })
    List<StuReturnMoney> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询stu_return_money表中数据行数
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("select count(*) " +
            "FROM stu_return_money st " +
            "JOIN student_manage s " +
            "ON st.student_id=s.student_id " +
            "JOIN school sh " +
            "ON st.school_id=sh.school_id " +
            "JOIN record r " +
            "ON st.record_id=r.record_id " +
            "JOIN account ac  " +
            "ON st.account_id=ac.account_id " +
            "JOIN class c " +
            "ON st.class_id=c.class_id " +
            "where 1=1 ${condition} ")
    int selectCount(@Param("condition") String condition);

    /**
     * 针对学员表(student_manage)进行操作
     * 根据学员名称查找其编号
     * @param studentName 学生姓名
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT student_id FROM student_manage WHERE student_name=#{studentName}")
    int selectByStudentName(@Param("studentName") String studentName);

    /**
     * 针对账户表(account)进行操作
     * 根据优惠项目查找其编号
     * @param accountType 优惠项目
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT account_id FROM account WHERE account_type=#{accountType}")
    int selectByAccountType(@Param("accountType")String accountType);

    /**
     * 针对学校表(school)进行操作
     * 根据学校名称查找其编号
     * @param schoolName 优惠项目
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT school_id FROM school WHERE school_name=#{schoolName}")
    int selectBySchoolName(@Param("schoolName")String schoolName);

    /**
     * 针对员工表(record)进行操作
     * 根据员工名称查找其编号
     * @param recordName 员工名称
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT record_id FROM record WHERE record_name=#{recordName}")
    int selectByRecordName(@Param("recordName")String recordName);

    /**
     * 针对班级表(class)进行操作
     * 根据班级名称查找其编号
     * @param className 班级名称
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT class_id FROM class WHERE class_name=#{className}")
    int selectByClassName(@Param("className")String className);

    /**
     * 得到所有校区信息
     * @return 校区对象集合
     */
    @Select("select school_id,school_name from school")
    @Results({
            @Result(id = true,column = "school_id",property = "schoolId"),
            @Result(column = "school_name",property = "schoolName")
    })
    List<School> selectAllGetSchool();

}
